package cn.edu.lcu.cs.designpattern.composite.transparency;

import java.util.List;

public class Leaf extends Node {
    public Leaf(String value) {
        setValue(value);
        setType(NODE_TYPE_LEAF);
    }

    public Leaf() {
        setType(NODE_TYPE_LEAF);
    }

    @Override
    public List<Node> getChildren() {
        throw new RuntimeException("叶节点没有孩子节点");
    }

    @Override
    public void add(Node child) {
        throw new RuntimeException("叶节点无法添加孩子节点");
    }

    @Override
    public void remove(Node child) {
        throw new RuntimeException("叶节点无法删除孩子节点");
    }

    @Override
    public Node getChild(int index) {
        throw new RuntimeException("叶节点没有孩子节点");
    }

    @Override
    public void print() {
        System.out.println("叶子结点【" + getValue() + "】");
    }

    @Override
    public void traversal(Node node) {
        print();
    }
}
